home *** CD-ROM | disk | FTP | other *** search
- /*==============================================================================
- Project: POV
-
- Version: 3
-
- File: AboutBox.c
-
- Description:
- Routines to Display the About Box.
- ------------------------------------------------------------------------------
- Author:
- Eduard [esp] Schwan
- ------------------------------------------------------------------------------
- from Persistence of Vision(tm) Ray Tracer
- Copyright 1996 Persistence of Vision Team
- ------------------------------------------------------------------------------
- NOTICE: This source code file is provided so that users may experiment
- with enhancements to POV-Ray and to port the software to platforms other
- than those supported by the POV-Ray Team. There are strict rules under
- which you are permitted to use this file. The rules are in the file
- named POVLEGAL.DOC which should be distributed with this file. If
- POVLEGAL.DOC is not available or for more info please contact the POV-Ray
- Team Coordinator by leaving a message in CompuServe's Graphics Developer's
- Forum. The latest version of POV-Ray may be found there as well.
-
- This program is based on the popular DKB raytracer version 2.12.
- DKBTrace was originally written by David K. Buck.
- DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
- ------------------------------------------------------------------------------
- Change History:
- 950420 [esp] Made really cool scrolling about box for 3.0.
- 960101 [esp] Handle multiple depth monitors properly
- 960122 [esp] rearranged toolbox calls so it wasn't dreadfully slow
- 960520 [esp] Enlarge text-scroll area so text smoothly scrolls onto screen
- ==============================================================================*/
-
- #define ABOUTBOX_C
-
- #include "AboutBox.h"
-
- #include <windows.h>
- #include <dialogs.h>
- #include <resources.h> // GetResource
- #include <TextUtils.h> // GetIndString
- #include <string.h> // strcpy
- #include <strings.h> // c2pstr
-
- #include "UtilLib.h"
- #include "PovMac.h" // gp2wWindow
- #include "fileprefs.h" // g_prefs2use
- #include "OptOut.h" // POV_RAY_VERSION
-
-
- #define STR_ABOUT_ID 130
- #define DITL_PICT_ID 1
-
- // how many pixels to scroll per update
- #define SCROLL_PIXELS 1
-
- // how many ticks to wait between updates
- #define kInterScrollTicks 3
-
- static FontInfo gFontInfo;
- static GWorldPtr gTextGW; // foreground scrolling text area
- static GWorldPtr gImageGW; // background image area
- static GWorldPtr gDestGW; // final mixing area
- static short gStringIndex;
- static short gScrollCount;
- static short gFontHeight;
- static Rect gTextR;
- static Rect gPictR;
- static PicHandle gPictH;
-
-
- // ---------------------------------------------------------------------
- // Returns the short version string in the application's version resource
- void GetAppVersionPString(short versID, Str31 versionString)
- {
- short oldRefNum;
- VersRecHndl versHandle; // VersRecHndl declared in types.h
-
- oldRefNum = CurResFile();
-
- /* Get the resource string from app, 'vers' versID (1 or 2) resource! */
- UseResFile(gAppRefNum); // gAppRefNum is from pov.c
- versHandle = (VersRecHndl)Get1Resource('vers',versID);
- if (versHandle)
- {
- HLock((Handle)versHandle);
- BlockMove((**versHandle).shortVersion, versionString, (**versHandle).shortVersion[0]+1);
- ReleaseResource((Handle)versHandle);
- /*
- if ( (**gPrefs2Use_h).progress >= eProgDebug )
- printf("-d vers rsrcID=%d, vers#=%d.%d[%d]%d versStr=%p\n",
- versID,
- (**versHandle).numericVersion.majorRev,
- (**versHandle).numericVersion.minorAndBugRev,
- (**versHandle).numericVersion.stage,
- (**versHandle).numericVersion.nonRelRev,
- versionString);
- */
- }
- else
- {
- versionString[0] = 0;
- SysBeep(1); // minor problem
- }
- // return to original resfile
- UseResFile(oldRefNum);
- } // GetAppVersionPString
-
-
- // ------------------------------------------------------------------
- static void SetupPortFont(GWorldPtr theGWorld)
- {
- SetGWorld(theGWorld, NULL); // 32bit QD
- // set the font in the grafport
- TextFont(times);
- TextSize(14);
- // find out font size info
- GetFontInfo(&gFontInfo);
- gFontHeight = gFontInfo.descent + gFontInfo.ascent + gFontInfo.leading;
- } // SetupPortFont
-
-
- // ---------------------------------------------------------------------
- static OSErr CreateOffScreens(WindowPtr screenWindow, Rect *theRect)
- {
- OSErr anError;
- // determine current screen depth
- short screenDepth = (**((CGrafPtr)screenWindow)->portPixMap).pixelSize;
- // create foreground text offscreen
- anError = NewGWorld(&gTextGW, screenDepth, theRect, NULL, NULL, 0);
- // create background image offscreen
- if (!anError)
- anError = NewGWorld(&gImageGW, screenDepth, theRect, NULL, NULL, 0);
- // create final mixing offscreen
- if (!anError)
- anError = NewGWorld(&gDestGW, screenDepth, theRect, NULL, NULL, 0);
- return anError;
- } // CreateOffScreens
-
-
- // ---------------------------------------------------------------------
- static void KillOffScreens(void)
- {
- if (gTextGW)
- {
- DisposeGWorld(gTextGW); // 32bit QD
- gTextGW = NULL;
- }
- if (gImageGW)
- {
- DisposeGWorld(gImageGW); // 32bit QD
- gImageGW = NULL;
- }
-
- if (gDestGW)
- {
- DisposeGWorld(gDestGW); // 32bit QD
- gDestGW = NULL;
- }
- } // KillOffScreens
-
-
- // ---------------------------------------------------------------------
- static OSErr SetupMarquee(DialogPtr myDialog, short pictID)
- {
- OSErr anError;
- GWorldPtr saveGWorld;
- GDHandle saveGD;
- short pItemType;
-
- GetGWorld(&saveGWorld, &saveGD);
-
- // Find font size information (Warning: ugly side-effect changes dialog's font!)
- SetupPortFont((GWorldPtr)myDialog);
-
- // find the pict and its rectangle size
- GetDialogItem(myDialog, pictID, &pItemType, (Handle*)&gPictH, &gPictR);
-
- // Create another Rect that is a little longer than the Pict, by one text line.
- // This will allow us to write the text just under the bottom of the window,
- // and scroll it into view.
- gTextR = gPictR;
- gTextR.bottom += gFontHeight;
-
- // set up offscreens with this rect
- anError = CreateOffScreens(myDialog, &gTextR);
-
- if (!anError)
- {
- // change text offscreen font to correct font
- SetupPortFont(gTextGW);
- // Clear text offscreen to white
- SetGWorld((CGrafPtr)gTextGW, NULL);
- LockPixels(((CGrafPtr)gTextGW)->portPixMap);
- EraseRect(&gTextR);
- UnlockPixels(((CGrafPtr)gTextGW)->portPixMap);
- // Fill image offscreen to white (in case there is transparent area)
- SetGWorld((CGrafPtr)gImageGW, NULL);
- LockPixels(((CGrafPtr)gImageGW)->portPixMap);
- EraseRect(&gTextR);
- // fill gworld with picture
- SetGWorld((CGrafPtr)gImageGW, NULL);
- HLock((Handle)gPictH);
- DrawPicture(gPictH, &gPictR);
- HUnlock((Handle)gPictH);
- UnlockPixels(((CGrafPtr)gImageGW)->portPixMap);
- }
-
- gScrollCount = 0;
- gStringIndex = 0;
-
- SetGWorld((CGrafPtr)saveGWorld, saveGD); // 32bit QD
- return anError;
- } // SetupMarquee
-
-
- // ---------------------------------------------------------------------
- static void KillMarquee(void)
- {
- KillOffScreens();
- } // KillMarquee
-
-
- // ---------------------------------------------------------------------
- static void UpdateMarquee(WindowPtr theAboutBox)
- {
- short strH, strV;
- short theTextMode = srcBic;
- RGBColor rgbBlack = {0x0000, 0x0000, 0x0000};
- // RGBColor rgbDrkBlue = {0x0000, 0x0000, 0x2000};
- RGBColor rgbCream = {0xfcff, 0xfeff, 0xffff};
- RGBColor rgbWhite = {0xffff, 0xffff, 0xffff};
- Str255 theString;
-
- // refill dest gworld with picture
- SetGWorld((CGrafPtr)gDestGW, NULL);
- RGBBackColor(&rgbWhite);
- RGBForeColor(&rgbBlack);
- CopyBits( (BitMap *)(*((CGrafPtr)gImageGW)->portPixMap),
- (BitMap *)(*((CGrafPtr)gDestGW)->portPixMap),
- &gPictR,
- &gPictR,
- ditherCopy, NULL);
-
- // scroll text up slowly
- SetGWorld((CGrafPtr)gTextGW, NULL);
- ScrollRect(&gTextR, 0, -SCROLL_PIXELS, NULL);
- gScrollCount += SCROLL_PIXELS;
- if (gScrollCount > gFontHeight)
- {
- // get next string
- gStringIndex++;
- GetIndString(theString, STR_ABOUT_ID, gStringIndex);
- if (!theString[0]) // past last string?
- gStringIndex = 0;
- // if string has a leading space, it is a heading, make it bold
- if (theString[1] == ' ') // Pascal string, remember!
- TextFace(bold);
- else
- TextFace(0);
- // center it
- strH = (gTextR.right - gTextR.left - StringWidth(theString)) >> 1;
- strV = gTextR.bottom-gFontInfo.descent-gFontInfo.leading-2;
- MoveTo(strH, strV);
- RGBBackColor(&rgbWhite);
- RGBForeColor(&rgbBlack);
- // display it
- DrawString(theString);
- gScrollCount = 0; // reset counter, wait for another word height
- }
-
- // Copy text over dest
- SetGWorld((CGrafPtr)gDestGW, NULL);
- RGBBackColor(&rgbCream);
- RGBForeColor(&rgbWhite);
- CopyBits( (BitMap *)(*((CGrafPtr)gTextGW)->portPixMap),
- (BitMap *)(*((CGrafPtr)gDestGW)->portPixMap),
- &gTextR,
- &gTextR,
- theTextMode, NULL);
-
- //
- // blast the offscreen to the window
- //
-
- SetGWorld((CGrafPtr)theAboutBox, NULL);
- RGBBackColor(&rgbWhite);
- RGBForeColor(&rgbBlack);
- CopyBits( (BitMap *)(*((CGrafPtr)gDestGW)->portPixMap),
- (BitMap *)*(((CGrafPtr)theAboutBox)->portPixMap),
- &gPictR,
- &gPictR,
- srcCopy, NULL);
-
-
- } // UpdateMarquee
-
-
- // ---------------------------------------------------------------------
- // Display Application About Box
- void DoAboutBox(void)
- {
- OSErr anError;
- long nextTick;
- Boolean allDone = false;
- Boolean specialAbout = false;
- DialogPtr myDialog;
- EventRecord anEvent;
- char povVers[16],
- compilerName[16],
- compDate[32];
- GWorldPtr saveGWorld;
- GDHandle saveGD;
-
- GetGWorld(&saveGWorld, &saveGD);
-
- // grab the dialog into memory
- myDialog = GetNewDialog(130, NULL, (WindowPtr) -1);
- if (myDialog)
- {
- /*
- // check for special info-key for about box
- if (gTheEvent.modifiers & optionKey)
- {
- specialAbout = true;
- PlayNotifySound();
- }
- */
- strcpy(compDate, "Compiled: ");
- strcat(compDate, __DATE__);
- c2pstr(compDate);
-
- strcpy(povVers, POV_RAY_VERSION);
- c2pstr(povVers);
-
- strcpy(compilerName, COMPILER_VER);
- c2pstr(compilerName);
-
- GetAppVersionPString(1, (StringPtr)povVers);
-
- ParamText( (StringPtr)povVers,
- (StringPtr)compilerName,
- (StringPtr)compDate,
- (StringPtr)gDistMessage);
-
- /* set up marquee graphics stuff */
- anError = SetupMarquee(myDialog, DITL_PICT_ID);
-
- /* Get into dialog's port & fiddle with fonts.. */
- SetPort((GrafPtr)myDialog);
- SetDialogFont(geneva); // Hack, should use GetFNum()
- TextFont(geneva); // Hack, should use GetFNum()
- TextSize(9);
-
- PositionWindow(myDialog, ewcDoCentering, eSameAsPassedWindow, (WindowPtr)gp2wWindow);
-
- ShowWindow(myDialog);
- DrawDialog(myDialog);
- nextTick = TickCount()+3*60; // wait several seconds before starting
-
- // lock down the pixmap memory
- LockPixels( ((CGrafPtr)gTextGW)->portPixMap );
- LockPixels( ((CGrafPtr)gImageGW)->portPixMap );
- LockPixels( ((CGrafPtr)gDestGW)->portPixMap );
-
- if (!anError)
- do {
- if (TickCount() >= nextTick)
- {
- nextTick = TickCount()+kInterScrollTicks; // wait N ticks between scrolls
- UpdateMarquee(myDialog);
- }
- if (Button() || EventAvail(mDownMask+keyDownMask, &anEvent))
- {
- FlushEvents(mDownMask+keyDownMask, 0);
- allDone = true;
- }
- } while (!allDone);
-
- UnlockPixels( ((CGrafPtr)gTextGW)->portPixMap );
- UnlockPixels( ((CGrafPtr)gImageGW)->portPixMap );
- UnlockPixels( ((CGrafPtr)gDestGW)->portPixMap );
-
- // Let some events sneak through before tearing down window.
- // This lets users do FKEY3 screen snapshots of about box, for example.
- {
- int k;
- for (k=1; k<5; k++)
- Cooperate(true);
- }
-
- KillMarquee();
-
- SetDialogFont(0); // Hack, should use GetFNum()
-
- DisposeDialog(myDialog);
- }
-
- // restore previous Grafport
- SetGWorld((CGrafPtr)saveGWorld, saveGD); // 32bit QD
-
- } // DoAboutBox
-
-
-